package com.gitee.attendance.util.base64;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;

import org.springframework.stereotype.Component;
@Component
public class Base64Util{

	public byte[] getFileInputStream(FileInputStream fis) throws IOException{
        byte[] b = new byte[1024];
        int n;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
		while ((n = fis.read(b)) != -1){
		    bos.write(b, 0, n);
        }
        bos.close();
        fis.close();
        return bos.toByteArray();
	}
    /**
     * 编码
     *
     * @param content
     * @return
     */
    public String encode(byte[] content) {
        return Base64.getEncoder().encodeToString(content);
    }
    /**
     * 解码
     *
     * @param source
     * @return
     */
    public byte[] decode(String source) {
		return Base64.getDecoder().decode(source);
    }
}
